package com.lzs.bootsafety.business.oss.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzs.bootsafety.business.oss.entity.SysConfig;
import com.lzs.bootsafety.business.oss.mapper.SysConfigMapper;
import com.lzs.bootsafety.business.oss.service.SysConfigService;
import com.lzs.bootsafety.business.sys.entity.SysUser;
import com.lzs.bootsafety.common.util.mybatis.MyBatisResultHandler;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
/**
 *  云存储配置
 *  @author  zhanshi Liu
 *  @date    2020/04/18
 *  @website www.jhmsona.cn
 *
 */
@Service
public class SysConfigServiceImpl implements SysConfigService{
    @Autowired
    private SysConfigMapper sysConfigMapper;
    @Autowired
    private SqlSessionFactory sqlSessionFactory;
    @Override
    public PageInfo<SysConfig> getConfigs(SysConfig sysConfig) {
        Integer page = sysConfig.getPage();
        Integer limit = sysConfig.getLimit();
        PageHelper.startPage(page = page == null ? 1 : page,limit = limit == null ? 10 : limit);
        Page<SysConfig> sysConfigList = sysConfigMapper.selectConfigs(sysConfig);
        return new PageInfo<SysConfig>(sysConfigList);
    }

    @Override
    public Map<String, Object> getConfigs() {
        SqlSession sqlSession = sqlSessionFactory.openSession(true);
        MyBatisResultHandler handler = new MyBatisResultHandler();
        sqlSession.select("findConfigs",handler);
        return handler.getResults();
    }

    @Override
    public int updateConfings(Map<String, Object> map) {
        return sysConfigMapper.modifyConfings(map);
    }


}
